package cn.concurrence;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 是否可重入锁 synchronized 和 ReentrantLock均为可重入
 *
 * @author summit
 * @since 2022/4/19 17:04
 */
public class ReentrantTest {

	public synchronized void test1() {
		System.out.println("开始测试1111");
		test2();
	}

	private synchronized void test2() {
		System.out.println("开始测试2222");
	}


	Lock lock = new ReentrantLock();

	public void test3() {
		lock.lock();
		try {
			System.out.println("开始测试33333");
			test4();
		} finally {
			lock.unlock();
		}
	}


	public void test4() {
		lock.lock();
		try {
			System.out.println("开始测试4444");
		} finally {
			lock.unlock();
		}
	}

}

class TestMain {
	public static void main(String[] args) {
		ReentrantTest t = new ReentrantTest();
		t.test1();

		ReentrantTest t1 = new ReentrantTest();
		t1.test3();
	}
}
